package cn.javav.sso.services;

import javax.annotation.Resource;

import org.springframework.stereotype.Component;

import cn.javav.sso.dao.UserDao;
import cn.javav.sso.entity.User;

@Component("UserServices")
public class UserServicesImpl implements UserServices{

	@Resource
	private UserDao userDao;
	
	@Override
	public void save(User user) {
		userDao.insert(user);
	}

	@Override
	public void delete(User user) {
		userDao.delete(user);
	}

	@Override
	public void update(User user) {
		userDao.update(user);
	}

	@Override
	public User getById(int id) {
		return userDao.getById(id);
	}

	@Override
	public User getByAccount(String account) {
		if("".equals(account)){
			return null;
		}
		return userDao.getByAccount(account);
	}

	@Override
	public User check(String account, String password) {
		if("".equals(account)){
			return null;
		}
		User user = getByAccount(account);
		if(user == null)
		{
			return null;
		}
		if(user.getPassword().equals(password))
		{
			return user;
		}
		return null;
	}

	public UserDao getUserDao() {
		return userDao;
	}

	public void setUserDao(UserDao userDao) {
		this.userDao = userDao;
	}

}
